// 引入App.vue
import Vue from 'vue'
// 引入路由
import Router from 'vue-router'
// 注册路由
Vue.use(Router)

var router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    // 登录页面的路由
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login')
    }, // 后台首页的路由
    {
      path: '/home',
      name: 'home',
      component: () => import('@/views/home')
    }
  ]
})
router.beforeEach((to, from, next) => {
  let token = window.sessionStorage.getItem('token')
  if (!token && to.path !== '/login') {
    return next('/login')
  }
  next()
})
export default router
